﻿using System.Linq.Expressions;

namespace Singer.Core.DataExtensions;

public static class LinqExtensions
{
    /// <summary>
    /// 当条件成立时，给查询表达式添加where条件
    /// </summary>
    /// <param name="condition">判断条件</param>
    /// <param name="expWhere">判断条件为true时，添加的where条件</param>
    public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> expWhere)
    {
        if(!condition)
            return query;
        return query.Where(expWhere);
    }
}
